''' 设备管理 '''
from dms import dmsservice as db
from flask import Blueprint, jsonify, redirect, url_for, request
import logging, requests
import sys, traceback, os, re

logger = logging.getLogger('app')



dms = Blueprint("dms", __name__, url_prefix="/api")

'''
设备管理页面组 start
'''
'''设备组页面 start'''
#获取设备组信息
@dms.route('/equipment/equipment_group',methods=['GET'])
def equipment_group():
    # 获取查询字符串参数，读取到的参数是字符串类型；用print(type(pageSize),type(pageCurrent),type(searchValue))验证
    logger.info("获取项目档案-项目列表页面数据")
    fordata = request.args.to_dict()
    result = db.equipment_group(fordata)
    return jsonify(result)

#删除设备组
@dms.route('/equipment/del_equipment_group',methods=['POST'])
def del_equipment_group():
    formdata = request.json
    result = db.del_equipment_group(formdata)
    return jsonify(result)

#创建设备组
@dms.route('/equipment/add_equipmentGroup',methods=['GET','POST'])
def add_equipmentGroup():
    formdata = request.json
    logger.info(formdata)
    # print(f"add project: {formdata}")
    result = db.add_equipmentGroup(formdata)
    return jsonify(result)

#更新设备组页面初始化
@dms.route('/equipment/init_equipmentGroup',methods=['GET','POST'])
def init_equipmentGroup():
    args = request.args.to_dict()
    logger.info(args)
    # print(args)
    result = db.init_equipmentGroup(args)
    return jsonify(result)

#更新设备组
@dms.route('/equipment/update_equipmentGroup',methods=['GET','POST'])
def update_equipmentGroup():
    formdata = request.json
    logger.info(formdata)
    result = db.update_equipmentGroup(formdata)
    return jsonify(result)
'''设备组页面 end'''

'''设备列表页面 start'''
#获取设备信息
@dms.route('/equipment/equipment_list',methods=['GET'])
def equipment_list():
    # 获取查询字符串参数，读取到的参数是字符串类型；用print(type(pageSize),type(pageCurrent),type(searchValue))验证
    logger.info("获取项目档案-项目列表页面数据")
    fordata = request.args.to_dict()
    result = db.equipment_list(fordata)
    return jsonify(result)

#获取选择班组下拉框选项
@dms.route('/equipment/groupOptions',methods=['GET'])
def equipment_groupOptions():
    selectProjectId = request.args.get('selectProject', default=None, type=int)
    result = db.equipment_groupOptions(selectProjectId)
    # print(res)
    return jsonify(result)

#删除设备组
@dms.route('/equipment/del_equipment',methods=['POST'])
def del_equipment():
    formdata = request.json
    result = db.del_equipment(formdata)
    return jsonify(result)

#创建设备组
@dms.route('/equipment/add_equipment',methods=['GET','POST'])
def add_equipment():
    formdata = request.json
    logger.info(formdata)
    # print(f"add project: {formdata}")
    result = db.add_equipment(formdata)
    return jsonify(result)

#更新设备页面初始化
@dms.route('/equipment/init_equipment',methods=['GET','POST'])
def init_equipment():
    args = request.args.to_dict()
    logger.info(args)
    # print(args)
    result = db.init_equipment(args)
    return jsonify(result)

#更新设备
@dms.route('/equipment/update_equipment',methods=['GET','POST'])
def update_equipment():
    formdata = request.json
    logger.info(formdata)
    result = db.update_equipment(formdata)
    return jsonify(result)

#获取人员信息
@dms.route('/equipment/employee_list',methods=['GET'])
def getemployeelist():
    param = {}
    param['pageSize'] = request.args.get('pageSize', default=10, type=int)
    param['pageCurrent']= request.args.get('page', default=1, type=int)
    param['searchValue'] = request.args.get('searchValue', default='', type=str)
    param['selectProjectId'] = request.args.get('selectProject', default=None, type=int)
    param['selectGroupId'] = request.args.get('selectGroup', default=None, type=int)
    param['equipid'] = request.args.get('equipid').strip(',')
    logger.info(param)
    result = db.getemployeelist(param)
    return jsonify(result)

#获取已下发人员信息
@dms.route('/equipment/releasedemployee_list',methods=['GET'])
def getreleasedemplist():
    param = {}
    param['pageSize'] = request.args.get('pageSize', default=10, type=int)
    param['pageCurrent']= request.args.get('page', default=1, type=int)
    param['equipid'] = request.args.get('equipid')
    logger.info(param)
    result = db.getreleasedemplist(param)
    return jsonify(result)

#下发至设备
@dms.route('/equipment/sendtoequip',methods=['GET','POST'])
def sendtoequip():
    # 将人员信息发送至设备中 
    formdata = request.json
    logger.info(formdata)
    result = db.sendtoequip(formdata)
    return jsonify(result)

#删除已下发人员信息
@dms.route('/equipment/deleteempequip',methods=['GET','POST'])
def deleteempequip():
    # 将人员信息发送至设备中 
    formdata = request.json
    logger.info(formdata)
    result = db.deleteempequip(formdata)
    return jsonify(result)


'''设备列表页面 end'''

'''
设备管理页面组 end
'''
